<template>
  <div class="app-container">
    <el-row :gutter="24">
      <splitpanes :horizontal="this.$store.getters.device === 'mobile'" class="default-theme">
        <!--部门数据-->
        <pane size="16">
          <el-col>
            <div class="head-container">
              <el-input v-model="deptName" placeholder="请输入部门名称" clearable size="small" prefix-icon="el-icon-search" style="margin-bottom: 20px" />
            </div>
            <div class="head-container">
              <el-tree :data="studeptOptions" :props="defaultProps" :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree" node-key="id" default-expand-all highlight-current @node-click="handleNodeClick" />
            </div>
          </el-col>
        </pane>
        <!--用户数据-->
        <pane size="84">
          <el-col>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="主分类" prop="deptId">
              <treeselect v-model="form.deptId" :options="enabledDeptOptions" :show-count="true" placeholder="请选择主分类" :default-expand-level="10"/>
            </el-form-item> -->
      <el-form-item label="客户名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="签订日期" prop="qddate">
        <el-date-picker clearable
          v-model="queryParams.qddate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择签订日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="接待人" prop="jdr">
        <el-input
          v-model="queryParams.jdr"
          placeholder="请输入接待人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同金额" prop="htje">
        <el-input
          v-model="queryParams.htje"
          placeholder="请输入合同金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="已收金额" prop="ysje">
        <el-input
          v-model="queryParams.ysje"
          placeholder="请输入已收金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="欠款金额" prop="qkje">
        <el-input
          v-model="queryParams.qkje"
          placeholder="请输入已收金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收款提醒日期" prop="sktxdate">
        <el-date-picker clearable
          v-model="queryParams.sktxdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择收款提醒日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="费用类型" prop="fylx">
        <el-select v-model="queryParams.fylx" placeholder="请选择费用类型" clearable>
          <el-option
            v-for="dict in dict.type.fee_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="收款提醒备注" prop="sktxbz">
        <el-input
          v-model="queryParams.sktxbz"
          placeholder="请输入收款提醒备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="sfzh">
        <el-input
          v-model="queryParams.sfzh"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生源" prop="sy">
        <el-input
          v-model="queryParams.sy"
          placeholder="请输入生源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="归属部门" prop="gsbm">
        <el-select v-model="queryParams.gsbm" placeholder="请选择归属部门">
          <el-option label="成人教育" value="成人教育"></el-option>
          <el-option label="专转本" value="专转本"></el-option>
          <el-option label="教育部" value="教育部"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="登记人" prop="djr">
        <el-input
          v-model="queryParams.djr"
          placeholder="请输入登记人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机" prop="sj">
        <el-input
          v-model="queryParams.sj"
          placeholder="请输入手机"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="初始填报院校" prop="cstbyx">
        <el-autocomplete
          v-model="queryParams.cstbyx"
          :fetch-suggestions="querySearch"
          placeholder="请选择或输入初始填报院校"
          clearable
          @select="handleSelect"
        />
      </el-form-item>
      <!-- <el-form-item label="返费" prop="ff">
        <el-input
          v-model="queryParams.ff"
          placeholder="请输入返费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="是否需要学位" prop="sfxyxw">
        <el-select v-model="queryParams.sfxyxw" placeholder="请选择是否需要学位" clearable>
          <el-option
            v-for="dict in dict.type.stu_if"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="返费备注" prop="ffbz">
        <el-input
          v-model="queryParams.ffbz"
          placeholder="请输入返费备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="填报专业" prop="tbzy">
        <el-input
          v-model="queryParams.tbzy"
          placeholder="请输入填报专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否参加校企" prop="sfcjxq">
        <el-select v-model="queryParams.sfcjxq" placeholder="请选择是否参加校企" clearable>
          <el-option
            v-for="dict in dict.type.stu_if"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="cjdate">
        <el-date-picker clearable
          v-model="queryParams.cjdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="修改时间" prop="xgdate">
        <el-date-picker clearable
          v-model="queryParams.xgdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择修改时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="班级" prop="bj">
        <el-input
          v-model="queryParams.bj"
          placeholder="请输入班级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="家长电话" prop="jzdh">
        <el-input
          v-model="queryParams.jzdh"
          placeholder="请输入家长电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否审批" prop="sp">
        <el-select v-model="queryParams.sp" placeholder="请选择是否审批" clearable>
          <el-option
            v-for="dict in dict.type.stu_if"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否退学" prop="tx">
        <el-select v-model="queryParams.tx" placeholder="请选择是否退学" clearable>
          <el-option
            v-for="dict in dict.type.stu_if"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建人" prop="cjr">
        <el-input
          v-model="queryParams.cjr"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['student:student:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['student:student:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['student:student:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['student:student:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
  

    <pagination
  v-show="total>0"
  :total="total"
  :page.sync="queryParams.pageNum"
  :limit.sync="queryParams.pageSize"
  @pagination="getList"
  class="pagination-top"
/>
    <el-table v-loading="loading" :data="studentList" @selection-change="handleSelectionChange" @row-click="handleRowClick">
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click.stop="handleUpdate(scope.row)"
            v-hasPermi="['student:student:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click.stop="handleDelete(scope.row)"
            v-hasPermi="['student:student:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="主分类" align="center" key="deptName" prop="dept.deptName" />
      <el-table-column label="客户名称" align="center" prop="name" />
      <el-table-column label="签订日期" align="center" prop="qddate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.qddate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="接待人" align="center" prop="jdr" />
      <el-table-column label="合同金额" align="center" prop="htje" />
      <el-table-column label="已收金额" align="center" prop="ysje" />
      <el-table-column label="欠款金额" align="center" prop="qkje">
      </el-table-column>
      <el-table-column label="收款提醒日期" align="center" prop="sktxdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sktxdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="费用类型" align="center" prop="fylx">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fee_type" :value="scope.row.fylx"/>
        </template>
      </el-table-column>
      <el-table-column label="收款提醒备注" align="center" prop="sktxbz" />
      <!-- <el-table-column label="附件上传" align="center" prop="fjsc" /> -->
      <el-table-column label="身份证号" align="center" prop="sfzh" />
      <el-table-column label="生源" align="center" prop="sy" />
      <el-table-column label="备注" align="center" prop="bz" />
      <el-table-column label="归属部门" align="center" prop="gsbm" />
      <el-table-column label="登记人" align="center" prop="djr" />
      <el-table-column label="手机" align="center" prop="sj" />
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="初始填报院校" align="center" prop="cstbyx" />
      <!-- <el-table-column label="返费" align="center" prop="ff" /> -->
      <el-table-column label="是否需要学位" align="center" prop="sfxyxw">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stu_if" :value="scope.row.sfxyxw"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="返费备注" align="center" prop="ffbz" /> -->
      <el-table-column label="填报专业" align="center" prop="tbzy" />
      <el-table-column label="是否参加校企" align="center" prop="sfcjxq">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stu_if" :value="scope.row.sfcjxq"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="cjdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cjdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="xgdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.xgdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="班级" align="center" prop="bj" />
      <el-table-column label="家长电话" align="center" prop="jzdh" />
      <!-- <el-table-column label="附件" align="center" prop="fj" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.fj" :width="50" :height="50"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="是否审批" align="center" prop="sp">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stu_if" :value="scope.row.sp"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="是否退学" align="center" prop="tx">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stu_if" :value="scope.row.tx"/>
        </template>
      </el-table-column> -->
      <el-table-column label="创建人" align="center" prop="cjr" />
    </el-table>
  </el-col>
</pane>
      </splitpanes>
    </el-row>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学生信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" >
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="客户名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入客户名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="主分类" prop="deptId">
              <treeselect v-model="form.deptId" :options="enabledDeptOptions" :show-count="true" placeholder="请选择主分类" :default-expand-level="10" />
            </el-form-item>
          </el-col>          
        </el-row>
        <el-row :gutter="24">          
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-radio-group v-model="form.sex">
                <el-radio
                  v-for="dict in dict.type.sys_user_sex"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机" prop="sj">
              <el-input v-model="form.sj" placeholder="请输入手机" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="接待人" prop="jdr">
              <el-input v-model="form.jdr" placeholder="请输入接待人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否参加校企" prop="sfcjxq">
              <el-radio-group v-model="form.sfcjxq">
                <el-radio
                  v-for="dict in dict.type.stu_if"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item :label=cstbyxlabel prop="cstbyx">
              <el-autocomplete
                v-model="form.cstbyx"
                :fetch-suggestions="querySearch"
                :placeholder="cstbyxplaceholder"
                clearable
                @select="handleSelect"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="填报专业" prop="tbzy">
              <el-input v-model="form.tbzy" placeholder="请输入填报专业" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="身份证号" prop="sfzh">
              <el-input v-model="form.sfzh" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生源" prop="sy">
              <el-input v-model="form.sy" placeholder="请输入生源" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <？el-row :gutter="24">          
            <el-col :span="12">
            <el-form-item label="登记人" prop="djr">
              <el-input v-model="form.djr" placeholder="请输入登记人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归属部门" prop="gsbm">
              <el-select v-model="form.gsbm" placeholder="请选择归属部门">
                <el-option label="成人教育" value="成人教育"></el-option>
                <el-option label="专转本" value="专转本"></el-option>
                <el-option label="教育部" value="教育部"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row> -->
        <el-row :gutter="24">
          <!-- <el-col :span="12">
            <el-form-item label="是否需要学位" prop="sfxyxw">
              <el-radio-group v-model="form.sfxyxw">
                <el-radio
                  v-for="dict in dict.type.stu_if"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="班级" prop="bj">
              <el-autocomplete
                v-model="form.bj"
                :fetch-suggestions="querySearchBanji"
                placeholder="请输入或选择班级"
                clearable
              />
              <el-cascader
                v-model="selectedBanji"
                :options="banjiOptions"
                :props="{ label: 'label', value: 'value', children: 'children' }"
                @change="handleBanjiChange"
                placeholder="请选择班级"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="家长电话" prop="jzdh">
              <el-input v-model="form.jzdh" placeholder="请输入家长电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="bz">
          <el-input v-model="form.bz" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="费用类型" prop="fylx">
              <el-radio-group v-model="form.fylx">
                <el-radio
                  v-for="dict in dict.type.fee_type"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="合同金额" prop="htje">
              <el-input v-model="form.htje" placeholder="请输入合同金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="已收金额" prop="ysje">
              <el-input v-model="form.ysje" placeholder="请输入已收金额" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="欠款金额" prop="qkje">
              <el-input v-model="form.qkje" placeholder="欠款金额" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收款提醒日期" prop="sktxdate">
              <el-date-picker clearable
                v-model="form.sktxdate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择收款提醒日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="签订日期" prop="qddate">
              <el-date-picker clearable
                v-model="form.qddate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择签订日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收款提醒备注" prop="sktxbz">
              <el-input v-model="form.sktxbz" placeholder="请输入收款提醒备注" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="返费" prop="ff">
              <el-input v-model="form.ff" placeholder="请输入返费" />
            </el-form-item>
          </el-col>          
          <el-col :span="12">
            <el-form-item label="返费备注" prop="ffbz">
              <el-input v-model="form.ffbz" placeholder="请输入返费备注" />
            </el-form-item>
          </el-col>
        </el-row> -->
        <!-- <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="创建时间" prop="cjdate">
              <el-date-picker clearable
                v-model="form.cjdate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择创建时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="修改时间" prop="xgdate">
              <el-date-picker clearable
                v-model="form.xgdate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择修改时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row> -->
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="附件" prop="fj">
              <image-upload :limit="50" v-model="form.fj"/>
            </el-form-item>
            <!-- <el-form-item label="附件上传" prop="fjsc">
          <file-upload v-model="form.fjsc"/>
        </el-form-item> -->
          </el-col>
          <el-col :span="12">
            <el-form-item label="修改人" prop="djr">
              <el-input v-model="form.djr" placeholder="请输入修改人" disabled/>
            </el-form-item>
            <el-form-item label="修改时间" prop="xgdate">
              <el-input v-model="form.xgdate" placeholder="请输入修改时间" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="center">交款信息信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddJkxx">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteJkxx">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="jkxxList" :row-class-name="rowJkxxIndex" @selection-change="handleJkxxSelectionChange" ref="jkxx">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="交款日期" prop="jkDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.jkDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择交款日期" />
            </template>
          </el-table-column>
          <el-table-column label="交款金额" prop="jkJine" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.jkJine" placeholder="请输入交款金额" />
            </template>
          </el-table-column>
          <el-table-column label="交款备注" prop="jkBz" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.jkBz" placeholder="请输入交款备注" />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStudent_zzbk, getStudent_zzbk, delStudent_zzbk, addStudent_zzbk, updateStudent_zzbk, deptTreeSelect, listBanji } from "@/api/student/student_zzbk";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { Splitpanes, Pane } from "splitpanes";
import "splitpanes/dist/splitpanes.css";
import { listSchool } from "@/api/student/school";

export default {
  name: "Student", 
  dicts: ['stu_if', 'fee_type', 'sys_user_sex'],
  components: { Treeselect, Splitpanes, Pane },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedJkxx: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 学生信息表格数据
      studentList: [],
      // 交款信息表格数据
      jkxxList: [],
      // 弹出层标题
      title: "",
      // 所有部门树选项
      studeptOptions: undefined,
      // 过滤掉已禁用部门树选项
      enabledDeptOptions: undefined,
      // 添加学校列表选项
      schoolOptions: [], 
      // 是否显示弹出层
      open: false,
      // 部门名称
      deptName: undefined,
      // 是否显示弹出层
      open: false,
      // 默认初始填报院校
      cstbyxlabel:'初始填报院校',
      // 默认输入初始填报院校
      cstbyxplaceholder:'请选择或输入初始填报院校',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: null,
        name: null,
        qddate: null,
        jdr: null,
        htje: null,
        ysje: null,
        qkje: null,
        sktxdate: null,
        fylx: null,
        sktxbz: null,
        sfzh: null,
        sy: null,
        bz: null,
        gsbm: '专转本',
        djr: null,
        sj: null,
        sex: null,
        cstbyx: null,
        ff: null,
        sfxyxw: null,
        ffbz: null,
        tbzy: null,
        sfcjxq: null,
        cjdate: null,
        xgdate: null,
        bj: null,
        jzdh: null,
        fj: null,
        sp: null,
        tx: null,
        cjr: null
      },
      // 表单参数
      form: {
        id: null,
        deptId: null,
        name: null,
        qddate: null,
        jdr: null,
        htje: null,
        ysje: null,
        qkje: null,
        sktxdate: null,
        fylx: null,
        sktxbz: null,
        sfzh: '暂无',
        sy: null,
        bz: null,
        gsbm: '专转本',
        djr: null,
        sj: null,
        sex: null,
        cstbyx: null,
        ff: null,
        sfxyxw: '否',
        ffbz: null,
        tbzy: null,
        sfcjxq: null,
        cjdate: null,
        xgdate: null,
        bj: null,
        jzdh: null,
        fj: null,
        sp: null,
        tx: null,
        cjr: null,
      },
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 表单校验
      rules: {
        name: [
          { required: true, message: "客户名称不能为空", trigger: "blur" }
        ],
        // jdr: [
        //   { required: true, message: "接待人不能为空", trigger: "blur" }
        // ],
        // sfzh: [
        //   { required: true, message: "身份证号不能为空", trigger: "blur" }
        // ],
        // djr: [
        //   { required: true, message: "登记人不能为空", trigger: "blur" }
        // ],
        // cstbyx: [
        //   { required: true, message: "初始填报院校不能为空", trigger: "blur" }
        // ],
        // sfxyxw: [ // 添加对 sfxyxw 字段的必填校验
        //   { required: true, message: "是否需要学位不能为空", trigger: "change" }
        // ],
        // sy: [ // 添加对 sy 字段的必填校验
        //   { required: true, message: "生源不能为空", trigger: "blur" }
        // ],
      },
      // 班级级联选择器相关数据
      selectedBanji: [], // 当前选中的班级值
      banjiOptions: [], // 班级级联选项
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    },
    'form.htje': {
      handler(newVal) {
        this.form.qkje = newVal - this.form.ysje;
      },
      immediate: true
    },
    'form.ysje': {
      handler(newVal) {
        this.form.qkje = this.form.htje - newVal;
      },
      immediate: true
    },
    'form.sfzh': {
    handler(newVal) {
      if (newVal && newVal.length === 18) {
        // 获取第17位字符（索引从0开始是第16位）
        const genderCode = parseInt(newVal.charAt(16));
        // 奇数男性，偶数女性
        this.form.sex = genderCode % 2 === 1 ? '0' : '1';
      }
    },
    immediate: true
    },
  },
  created() {
    this.getList();
    this.getDeptTree();
    this.showUserName();
    this.getSchoolList(); // 获取学校列表
    this.getBanjiOptions(); // 获取班级级联选项
  },
  computed: {
    qkje: {
      get() {
        return this.form.htje - this.form.ysje;
      },
      set(value) {
        this.form.qkje = value;
      }
    }
  },
  methods: {
    showUserName() {
      // 在方法中获取用户名
      const username = this.$store.state.user.nickName;
    },
    /** 查询学生信息列表 */
    getList() {
      this.loading = true;
      listStudent_zzbk(this.queryParams).then(response => {
        this.studentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询学校信息列表 */
    getSchoolList() {
      listSchool().then(response => {
        this.schoolOptions = response.rows.map(school => ({
          value: school.name,
          label: school.name
        }));
      });
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.studeptOptions = response.data;
        this.enabledDeptOptions = this.filterDisabledDept(JSON.parse(JSON.stringify(response.data)));
      });
    },
    // 过滤禁用的部门
    filterDisabledDept(deptList) {
      return deptList.filter(dept => {
        if (dept.disabled) {
          return false;
        }
        if (dept.children && dept.children.length) {
          dept.children = this.filterDisabledDept(dept.children);
        }
        return true;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.handleQuery();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deptId: null,
        name: null,
        qddate: null,
        jdr: null,
        htje: null,
        ysje: null,
        qkje: null,
        sktxdate: null,
        fylx: null,
        sktxbz: null,
        sfzh: '暂无',
        sy: null,
        bz: null,
        gsbm: '专转本',
        djr: null,
        sj: null,
        sex: null,
        cstbyx: null,
        ff: null,
        sfxyxw: '否',
        ffbz: null,
        tbzy: null,
        sfcjxq: null,
        cjdate: null,
        xgdate: null,
        bj: null,
        jzdh: null,
        fj: null,
        sp: null,
        tx: null,
        cjr: null
      };
      this.jkxxList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.form.qkje = this.form.htje - this.form.ysje; // 初始化 qkje
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      
      this.queryParams.deptId = undefined;
      this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },// 在methods中添加方法判断是否是"其他证书"或其子节点
    isOtherCertificate(deptId) {
      // 1. 先遍历部门树找到"其他证书"节点
      const findNode = (nodes) => {
        for (const node of nodes) {
          if (node.label === '其他证书') return node
          if (node.children) {
            const found = findNode(node.children)
            if (found) return found
          }
        }
        return null
      }
      
      // 2. 获取该节点及其所有子节点的ID
      const getAllChildIds = (node) => {
        const ids = [node.id]
        if (node.children) {
          node.children.forEach(child => {
            ids.push(...getAllChildIds(child))
          })
        }
        return ids
      }

      // 3. 判断当前deptId是否在ID集合中
      const targetNode = findNode(this.studeptOptions)
      if (!targetNode) return false
      
      const allIds = getAllChildIds(targetNode)
      return allIds.includes(deptId)
    },
    
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      if (this.isOtherCertificate(this.queryParams.deptId)) {
      this.cstbyxlabel='所需证书';
      this.cstbyxplaceholder='请选择或输入所需证书';
      }else{
      this.cstbyxlabel='初始填报院校';
      this.cstbyxplaceholder='请选择或输入初始填报院校';
      }
      this.form.deptId = this.queryParams.deptId;
      this.form.cjr = this.$store.state.user.name;
      this.form.djr = this.$store.state.user.name;
      this.form.qddate = this.parseTime(new Date(), '{y}-{m}-{d}'); // 签订日期
      this.form.cjdate = this.parseTime(new Date(), '{y}-{m}-{d}'); // 创建时间
      this.form.xgdate = this.parseTime(new Date(), '{y}-{m}-{d}'); // 修改时间
      this.form.sp = '否';
      this.form.tx = '否';
      this.form.cstbyx = ''; // 设置初始填报院校默认值为“无”
      this.open = true;
      this.title = "添加学生信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStudent_zzbk(id).then(response => {
        this.form = response.data;
        this.jkxxList = response.data.jkxxList;
        this.open = true;
        this.title = "修改学生信息";
        this.form.djr = this.$store.state.user.name;//修改人
        this.form.xgdate = this.parseTime(new Date(), '{y}-{m}-{d}'); // 修改时间
        this.form.sp = '否';
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 添加已收金额不能大于合同金额的验证
          if (+this.form.ysje > +this.form.htje) {
            this.$modal.msgError("已收金额不能大于合同金额");
            return;
          }
          this.form.jkxxList = this.jkxxList;
          if (this.form.id != null) {
            updateStudent_zzbk(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudent_zzbk(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 审核按钮 */
    check() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.fjsc = this.form.fjsc.join(",");
          this.form.sp = '是';
          this.form.jkxxList = this.jkxxList;
          if (this.form.id != null) {
            updateStudent_zzbk(this.form).then(response => {
              this.$modal.msgSuccess("审核成功");
              this.open = false;
              this.getList();
            });
          } 
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除学生信息编号为"' + ids + '"的数据项？').then(function() {
        return delStudent_zzbk(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 交款信息序号 */
    rowJkxxIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 交款信息添加按钮操作 */
    handleAddJkxx() {
      let obj = {};
      obj.jkDate = "";
      obj.jkJine = "";
      obj.jkBz = "";
      this.jkxxList.push(obj);
    },
    /** 交款信息删除按钮操作 */
    handleDeleteJkxx() {
      if (this.checkedJkxx.length == 0) {
        this.$modal.msgError("请先选择要删除的交款信息数据");
      } else {
        const jkxxList = this.jkxxList;
        const checkedJkxx = this.checkedJkxx;
        this.jkxxList = jkxxList.filter(function(item) {
          return checkedJkxx.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleJkxxSelectionChange(selection) {
      this.checkedJkxx = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('student/student/export', {
        ...this.queryParams
      }, `student_${new Date().getTime()}.xlsx`)
    },
    handleRowClick(row) {
      this.handleUpdate(row);
    },
    querySearch(queryString, cb) {
      const results = queryString
        ? this.schoolOptions.filter(school => school.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0)
        : this.schoolOptions;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    handleSelect(item) {
      console.log(item);
    },
    /** 获取班级级联选项 */
    getBanjiOptions() {
      listBanji().then(response => {
        const data = response.rows;
        const xuexiaoMap = new Map();
        data.forEach(item => {
          if (!xuexiaoMap.has(item.xuexiao)) {
            xuexiaoMap.set(item.xuexiao, { label: item.xuexiao, value: item.xuexiao, children: [] });
          }
          const fenleiMap = xuexiaoMap.get(item.xuexiao).children.find(f => f.value === item.fenlei);
          if (!fenleiMap) {
            xuexiaoMap.get(item.xuexiao).children.push({ label: item.fenlei, value: item.fenlei, children: [] });
          }
          const zhuanyeMap = xuexiaoMap.get(item.xuexiao).children.find(f => f.value === item.fenlei).children.find(z => z.value === item.zhuanye);
          if (!zhuanyeMap) {
            xuexiaoMap.get(item.xuexiao).children.find(f => f.value === item.fenlei).children.push({ label: item.zhuanye, value: item.zhuanye, children: [] });
          }
          const banjiMap = xuexiaoMap.get(item.xuexiao).children.find(f => f.value === item.fenlei).children.find(z => z.value === item.zhuanye).children.find(b => b.value === item.banji);
          if (!banjiMap) {
            xuexiaoMap.get(item.xuexiao).children.find(f => f.value === item.fenlei).children.find(z => z.value === item.zhuanye).children.push({ label: item.banji, value: item.banji });
          }
        });
        this.banjiOptions = Array.from(xuexiaoMap.values());
      });
    },

    /** 班级级联选择器变化时触发 */
    handleBanjiChange(value) {
      if (value.length === 4) {
        const [xuexiao, fenlei, zhuanye, banji] = value;
        this.form.bj = `${xuexiao} ${fenlei} ${zhuanye} ${banji}`;
      } else {
        this.form.bj = '';
      }
    },

  }
};
</script>